<template>
	<view class="loginFcard">
		<image style="width: 250upx;height: 250upx;margin-left: 250upx;margin-top: 100upx;" src="../../static/image/er.png"
		 mode=""></image>
		<view class="login_1">
			<view style="text-align: center;font-size: 45upx;font-weight: 600;margin: 20upx 0;">
				注册
			</view>
			<view>
				<u-line color="red" />
				<u-field v-model="mobile" label="手机号" placeholder="请填写手机号">
				</u-field>
				<u-line color="red" />
				<text style="color:red;font-size:23rpx;margin-left:25rpx;text-align:center">本程序需要注册登录才能关联个人动态二维码，远程开门服务</text>

				<view class="zhuce" @click="zhuceFun">
					注册
				</view>
				<view class="cxdl" @click="Login">
					已注册，重新登录
				</view>
				<view class="tcout">
					<navigator style="transform: scale(0.8,0.8);width: 100%;height: 100%;" open-type="exit" target="miniProgram">退出程序</navigator>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import http from '../../common/vmeitime-http/index.js';
	import {
		Base64Encrypt,
		Base64Decrypt,
		Decrypt,
		EncryptAES,
		SHA256,
		RSA_encrypt,
		RSA
	} from '../../utils/crypto_RSA_AES.js'
	export default {
		data() {
			return {
				mobile: ''
			}
		},
		methods: {
			
			zhuceFun() {
				let that = this;
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						// console.log(loginRes.code);
						that.$Fpublic.code = loginRes.code;
						let parma = {
							'MobilePhone': that.mobile,
							'Code': loginRes.code,
							Loginciphertext: RSA_encrypt().encrypt('')
						}
						http.Logup(parma).then(res => {
							if (res.data.result == 1) {
								that.$Fpublic.cardId = that.mobile;
								uni.setStorageSync('Cardid', that.mobile);
								// that.$Fpublic.headerCookie = res.cookies[0].split(';')[0].split('=')[1];
								// uni.setStorageSync('cooks', that.$Fpublic.headerCookie);
								// uni.setStorageSync('AKey', res.data.Data.AKey)
								// uni.setStorageSync('AIV', res.data.Data.AIV);
								that.Login()
								// uni.switchTab({
								//     url: '/pages/fcard/fcard'
								// });
							}else{
								
							}
						})
					}
				})
				
			},
			Login(){
				let that =this;
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						// console.log(loginRes.code);
						that.$Fpublic.code = loginRes.code;
						let parma = {
							'code': that.$Fpublic.code,
							Loginciphertext: RSA_encrypt().encrypt('')
						}
						http.login(parma).then(res => {
							console.error(res.cookies[0].split(';')[0].split('=')[1])
							that.loading = false;
							if (res.data.result == 1) {
								that.$Fpublic.cardId = res.data.Data.CardData;
								uni.setStorageSync('Cardid', res.data.Data.CardData);
								that.$Fpublic.headerCookie = res.cookies[0].split(';')[0].split('=')[1];
								uni.setStorageSync('cooks', that.$Fpublic.headerCookie);
								uni.setStorageSync('AKey', res.data.Data.AKey)
								uni.setStorageSync('AIV', res.data.Data.AIV)
								uni.switchTab({
								    url: '/pages/fcard/fcard'
								});
							}
				
						}).catch(err => {
							// console.error(err)
							that.loading = false;
						})
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.loginFcard {
		width: 700upx;
		height: 100%;
		margin-left: 25upx;

		.tcout {
			width: 90%;
			height: 90upx;
			line-height: 90upx;
			font-size: 30upx;
			background-color: #f0f0f0;
			color: #000;
			text-align: center;
			margin: 20upx 0;
			margin-left: 5%;
		}

		.zhuce,
		.cxdl {
			text-align: center;
			width: 90%;
			height: 90upx;
			line-height: 90upx;
			font-size: 30upx;
			background-color: #19BE6B;
			color: #fff;
			margin: 20upx 0;
			margin-left: 5%;
		}
	}
</style>
